package com.petecat.interchan.base.warning.rule.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.petecat.interchan.base.warning.rule.service.IWarningRuleService;
import com.petecat.interchan.core.constans.Global;
import com.petecat.interchan.core.controller.BaseController;
import com.petecat.interchan.protocol.GlobalHeader;
import com.petecat.interchan.protocol.Result;
import com.petecat.interchan.protocol.base.rule.dto.BsWarningRuleQryDTO;
import com.petecat.interchan.protocol.base.rule.vo.BsWarningRuleQryVO;
import com.petecat.interchan.protocol.base.rule.vo.BsWarningRuleTreeVO;
import com.petecat.interchan.protocol.data.PageVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@Api("预警权限管理")
@RequestMapping("/base/warningrule")
public class WarningRuleController extends BaseController{
	
	@Autowired
	private IWarningRuleService ruleService;
	
	@SuppressWarnings("unchecked")
	@ApiOperation("分页查询预警权限信息")
	@GetMapping("/queryWarningRuleByPage")
	public Result<PageVO<BsWarningRuleQryVO>> queryWarningRuleByPage(@ModelAttribute BsWarningRuleQryDTO bsWarningConfigQryDTO,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		bsWarningConfigQryDTO.setUserId(userInfo.getUserId());
		PageVO<BsWarningRuleQryVO> pageVO = ruleService.queryWarningRuleByPage(bsWarningConfigQryDTO);
		return (Result<PageVO<BsWarningRuleQryVO>>) Result.ok(pageVO);
	}
	
	@SuppressWarnings("unchecked")
	@ApiOperation("TREE查询预警权限")
	@GetMapping("/queryWarningRuleTree")
	public Result<PageVO<BsWarningRuleTreeVO>> queryWarningRuleTree(@ModelAttribute BsWarningRuleQryDTO bsWarningConfigQryDTO,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		bsWarningConfigQryDTO.setUserId(userInfo.getUserId());
		PageVO<BsWarningRuleTreeVO> pageVO = ruleService.queryWarningRuleTree(bsWarningConfigQryDTO);
		return (Result<PageVO<BsWarningRuleTreeVO>>) Result.ok(pageVO);
	}
	
	
}
